<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?python
    from mnemoply.utils import replace_query_var
    from genshi.input import HTML
?>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:xi="http://www.w3.org/2001/XInclude"
      xmlns:py="http://genshi.edgewall.org/">
    <xi:include href="../master.html" />

<head>
    <title><span py:strip="True">Lookup</span> &laquo;${title}&raquo;</title>
    <script type="text/javascript" src="/static/javascript/lookup.js"></script>
</head>

    <span py:def="navigation()">
    <span py:if="page_total == 0">No records</span>

    <span py:if="page_total > 1">
        <span py:if="page_current > 1" class="noprint">
            <a href="${replace_query_var('save_list_args', page=1)}">&lt;&lt;</a>
            &nbsp;&nbsp;
            <a href="${replace_query_var('save_list_args', page=page_current - 1)}">Prev</a>
        </span>

        <span py:if="page_current == 1" class="noprint">
            &lt;&lt;
            &nbsp;&nbsp;
            <span>Prev</span>
        </span>

        <span>${page_current}</span> <span>of</span> <span>${page_total}</span>

        <span py:if="page_current &lt; page_total" class="noprint">
            <a href="${replace_query_var('save_list_args', page=page_current + 1)}">Next</a>
            &nbsp;&nbsp;
            <a href="${replace_query_var('save_list_args', page=page_total)}">&gt;&gt;</a>
        </span>

        <span py:if="page_current == page_total" class="noprint">
            <span>Next</span>
            &nbsp;&nbsp;
            &gt;&gt;
        </span>
    </span>
</span>

<body onload="focusFirstField();">
    <script type="text/javascript">
        no_items_selected_message = '${_("You need to select at least one record")}'
    </script>
    <div>AAAAAAAAAAAAAAAAAAAAAAAAAAA</div>

<div align="center">

    <h3 py:if="title">
        <span>Lookup</span> &laquo;<span>${title}</span>&raquo;
    </h3>
    <div>  <span>${ET(form())}</span>
    </div>
    <span>${navigation()}</span>

    <br />

    <span py:if="show_actions" class="noprint">
        <a href="#" onclick="toggleAll('objid_', true); return false;">Select all</a> | <a
        href="#" onclick="toggleAll('objid_', false); return false;">Clear all</a>
    </span>

    <br />

    <span>Total ${total} records, ${len(records)} shown</span>

    <table class="maintable">
    <thead>
        <tr>
            <td>
                &nbsp;
            </td>

            <td py:for="column_index, col in enumerate(visible_columns)" onmouseout="bgColor=''" onmouseover="bgColor='#bbbbee'" nowrap="nowrap">
                <?python
                    hide = col.hide
                    sort_symbol = ''

                    if order_by == col.name:
                        if order_asc == 1:
                            sort_symbol = '&#8593; '
                        else:
                            sort_symbol = '&#8595; '

                        href = replace_query_var('save_list_args', asc=int(not order_asc))
                    else:
                        href = replace_query_var('save_list_args', sort=col.name)

                    href_move_right = replace_query_var('save_list_args', move_right_vc=visible_columns.index(col))
                    href_move_left  = replace_query_var('save_list_args', move_left_vc=visible_columns.index(col))
                ?> 
                <a py:if="column_index > 0"
                    class="move_vc" href="${href_move_left}">←</a>
                <span py:if="column_index == 0">&nbsp;&nbsp;&nbsp;</span>


               <a href="${href}"><span>${HTML(sort_symbol)}</span><span class="col_caption"> <pre>${col.caption}</pre> </span></a>

                <a py:if="len(visible_columns) - 1 > column_index"
                    class="move_vc" href="${href_move_right}">→</a>
                <span py:if="column_index == len(visible_columns) - 1">&nbsp;&nbsp;&nbsp;</span>
            </td>
            <td>
            &nbsp;
            </td>
        </tr>
        <tr style="display: none">
            <form id="filters" name="filter" action="save_list_args">
                <td>
                    <img src="/static/images/dots.gif" class="pseudo_link" border="0" vspace="0" hspace="0"
                         onclick="montre('smenu9');" onmouseout="hide_menu_delay();"/>
                    <table id="smenu9" onmouseover="hide_menu_cancel();" onmouseout="hide_menu_delay();">
                        <tr onmouseout="bgColor=''" onmouseover="bgColor='#bbbbee'">
                            <td onclick="createURL();return false;" class="pseudo_link">
                                <span>Save As</span>
                            </td><td>&nbsp;</td>
                        </tr>
                        <tr class="menu_item" py:for="n, fil in enumerate(user_filters)"
                            onmouseout="bgColor=''" onmouseover="bgColor='#bbbbee'">
                            <td class="pseudo_link" onclick="document.location='load_filter?load_filter=${n}'">${fil.name}</td>
                            <td width="10px"><a href="delete_filter?delete_filter=${n}">x</a></td>
                        </tr>
                    </table>
                </td>

                <td  py:for="col in visible_columns">
                     <input  id="${col.name}"
                            name="${str('flt_' + col.name)}"
                            value="${str(filters.get(col.name, ''))}"
                            onkeypress="return enterSubmit(event, this.form)"
                            size="${getattr(col, 'size', '15')}" />
                </td>
                <td>
                    <button type="submit">
                        <img src="/static/images/enter.gif" border="0" hspace="0" vspace="0" />
                    </button>
                </td>

            </form>
        </tr>
    </thead>

    <tbody>
        <tr py:for="record in records"
            onmouseout="bgColor=''"
            onmouseover="bgColor='#bbbbee'">
            
            <td>
                <input type="checkbox" name="objid_${record[0]}" />
            </td>
            <td py:for="value in record[1:]" >
                <span></span>
                <a py:if="value is not None" href="${record[0]}/" py:content="value" class="withouth_decoration"></a>
                <span py:strip="True" py:if="value is None">&nbsp;</span>
            </td>
            <td nowrap="nowrap">
                <img  py:if="is_delete_object" src="/static/images/trash.png" class="pseudo_link"
                    alt="Delete" border="0" hspace="4" onclick="if (confirm('Are you sure you want to delete?'))
                    { parent.location='${record[0]}/delete'; }" />
            </td>
        </tr>
    </tbody>
    </table>

    <span>Total ${total} records, ${len(records)} shown</span>

    <br />

    <span>${navigation()}</span>

    <br />

    <div class="tabber noprint">
        <div class="tabbertab">
            <h2>Settings</h2>

            <table border="0" cellpadding="2" cellspacing="0">
                <tbody>

                <tr py:if="len(columns) > len(visible_columns)">
                    <th>
                        <label class="fieldlabel">Show column</label>
                    </th>
                    <td>
                        <form action="save_list_args" method="POST">
                            <select name="add_vc" onchange="this.form.submit()">
                                <option value="-1">(Select column)</option>

                                <option py:for="n, col in enumerate(columns)"
                                    py:if="col not in visible_columns"
                                    value="${n}"
                                    py:content="col.caption" />
                            </select>
                        </form>
                    </td>
                </tr>

                <tr py:if="len(visible_columns) > 1">
                    <th>
                        <label class="fieldlabel">Hide column</label>
                    </th>
                    <td>
                        <form action="save_list_args" method="POST">
                            <select name="delete_vc" onchange="this.form.submit()">
                                <option value="-1">(Select column)</option>

                                <option py:for="n, col in enumerate(columns)"
                                    py:if="col in visible_columns and not col.hide"
                                    value="${n}"
                                    py:content="col.caption" />
                            </select>
                        </form>
                    </td>
                </tr>

                <tr>
                    <th>
                        <label class="fieldlabel">Records per page</label>
                    </th>
                    <td>
                        <form name="page_select_form" action="save_list_args" method="POST">
                            <select name="per_page" onchange="this.form.submit()">
                                <option value="100">(custom)</option>

                                <option py:for="n in per_page_values"
                                    value="${n}"
                                    py:content="n"
                                    py:attrs="n == per_page and {'selected':'selected'} or {}"
                                />
                            </select>
                        </form>
                    </td>
                </tr>

                </tbody>
            </table>

            <a href="save_list_args?clear=1">Reset settings to defaults</a>
        </div>

        <loop py:for="ma in mass_actions" py:strip="True">
            <div py:if="ma.display_on_lookup" class="tabbertab">
                <h2>${ma.title}</h2>
                <?python
                    form_code = ma.form.display(value=ma_form_values,
                        action=make_mass_action_url(ma.name),
                        form_attrs={'onsubmit': "return collectIDs('objid_', this);"},
                    )
                ?>
                <span>${ET(form_code)}</span>
                <img src="/static/images/dots.gif" class="pseudo_link" border="0" vspace="0" hspace="0"
                      onclick="document.getElementById('${ma.name}').style.display == 'block' ?
                               document.getElementById('${ma.name}').style.display = 'none' :
                               document.getElementById('${ma.name}').style.display = 'block';" />
                <span id="${ma.name}"
                      style="display: none"
                      py:content="'%s/%s' % (ma.target_class.getModelName(), ma.name)" />
            </div>
        </loop>
    </div>

    <br />

    <center>
        <a href="list_rds?">Export to excel</a>
    </center>
</div>
</body>
</html>
